关于Matlab:如何在Simulink中关闭代码生成? (独立代码生成不支持该功能) 您所在的位置:网站首页 vivo gsm关闭代码 关于Matlab:如何在Simulink中关闭代码生成? (独立代码生成不支持该功能)

关于Matlab:如何在Simulink中关闭代码生成? (独立代码生成不支持该功能)

2024-05-07 13:03| 来源: 网络整理| 查看: 265

我正在创建一个模拟,并将自己移植到另一种语言。因此,我不需要使用Simulink的代码生成功能。

如何关闭允许代码生成的尝试?

例如,我在MATLAB Function块中有以下代码:

123456789101112131415161718function OutImage = ResizeCropPad(InImage, Width, Height) %#codegen     %coder.extrinsic('imresize');     % resizing to defined height     scale = Height/size(InImage,1);     InImage = imresize(InImage, scale);     % cropping to defined width     if Widthsize(InImage,2)         b = floor((Width-size(InImage,2))/2);         InImage = InImage(:,b:b+Width-1,:);     end     OutImage = InImage;

并给出错误

The function 'imresize' is not supported for standalone code generation. See the documentation for coder.extrinsic to learn how you can use this function in simulation.

如果取消注释coder.extrinsic('imresize')行,则会收到新错误

Expected either a logical, char, int, fi, single, or double. Found an mxArray. MxArrays are returned from calls to the MATLAB interpreter and are not supported inside expressions. They may only be used on the right-hand side of assignments and as arguments to extrinsic functions.

使用if寻址第11行。

为什么?是否可以完全禁用代码生成,例如在模型级别?

相关讨论 在使用MATLAB Function模块的情况下,您无法关闭代码生成。块的工作方式是将m代码转换为c代码(或在c代码中package任何定义为code.extrinsic的内容),并运行该编译后的代码作为模拟的一部分。它与整个模型的代码生成无关(如果您使用Simulink Coder而不是自己进行代码生成,则会发生这种情况)。

在调用imresize函数之前,需要取消注释coder.extrinsic('imresize');行并声明/初始化InImage变量。有关更多信息,请参见将mxArrays转换为已知类型。

编辑注释中的以下讨论:

以下应能工作:

1234567891011121314151617function OutImage = ResizeCropPad(InImage, Width, Height) %#codegen     coder.extrinsic('imresize');     % resizing to defined height     scale = Height/size(InImage,1);     OutImage = InImage;     OutImage = imresize(InImage, scale);     % cropping to defined width     if Widthsize(OutImage,2)         b = floor((Width-size(outImage,2))/2);         OutImage = OutImage(:,b:b+Width-1,:);     end 相关讨论 另请参阅mathworks.co.uk/matlabcentral/answers/ 由于InImage是函数的输入参数,这是否意味着它在调用imresize之前已经被初始化? 对不起,我没看到。您可能想使用另一个变量,而不是在调用imresize时覆盖输入。为什么不立即使用OutImage而不是等到函数结束呢?您可以在调用imresize函数之前通过OutImage = InImage对其进行初始化。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有